<%@ page contentType="text/html;charset=UTF-8" language="java"  import="java.util.*" trimDirectiveWhitespaces="true" %>
<%@include file="/WEB-INF/pages/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>权限管理</title>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <%@include file="/WEB-INF/pages/common/commonCss.jsp"%>
  <link rel="stylesheet" href="${basePath}/resources/css/uniform.css" />
  <link rel="stylesheet" href="${basePath}/resources/css/select2.css" />
  <link rel="stylesheet" href="${basePath}/resources/css/matrix-style.css" />
  <link rel="stylesheet" href="${basePath}/resources/css/matrix-media.css" />
  <link rel="stylesheet" href="${basePath}/resources/css/admin/list.css" />
  <!--引入树的js和css-->
  <link rel="stylesheet" href="${basePath}/resources/sg/tree/tm_tree.css"/>

</head>

<body>

<!--Header-part-->
<%@include file="/WEB-INF/pages/common/head.jsp"%>


<!--sidebar-menu-->
<%@include file="/WEB-INF/pages/common/left.jsp"%>

<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> 首页</a> <a href="#" class="current">权限管理</a> </div>
    <%--<h1>权限管理</h1>--%>
  </div>

  <div class="container-fluid">

    <hr>
    <div class="row-fluid">

      <div class="span12">
        <a class="btn btn-primary"  data-toggle="modal" data-target="#myModal">新增一级权限</a>

        <div class="widget-box">

          <div id="permissiontree"></div>
        </div>
      </div>
    </div>
  </div>
</div>

<!--新增权限模态框-->
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">×
        </button>
        <h4 class="modal-title" id="myModalLabel">
          新增权限
        </h4>
      </div>
      <form id="myForm" method="post" action="${adminPath}/permission/save">
        <input type="hidden" name="parentId" id="parentId">
        <div class="modal-body">
          <p class="row-fluid"><span class="span2">权限名称</span> <input type="text"  name="name" style="height: 2rem;" class="span7" ></p>
          <p class="row-fluid"><span class="span2">权限描述</span> <input type="text" name="description" style="height: 2rem;" class="span7"  ></p>
          <p class="row-fluid"><span class="span2">url</span> <input type="text" name="url"  style="height: 2rem;" class="span7"  ></p>
          <p class="row-fluid"><span class="span2">模块</span> <input type="text" name="model"  style="height: 2rem;" class="span7"  ></p>
        </div>
      </form>
      <div class="modal-footer">
        <button type="button" class="btn btn-default"
                data-dismiss="modal">关闭
        </button>
        <button type="button" class="btn btn-primary" onclick="permission.savePerssion()">
          保存
        </button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!--编辑权限模态框-->
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">×
        </button>
        <h4 class="modal-title" id="myModalLabel2">
          编辑权限
        </h4>
      </div>
      <form id="myForm2" method="post" action="${adminPath}/permission/update">
        <input type="hidden" name="Id" id="thisId">
        <div class="modal-body">
          <p class="row-fluid"><span class="span2">权限名称</span> <input type="text" id="thisName" name="name" style="height: 2rem;" class="span7"></p>
          <p class="row-fluid"><span class="span2">权限描述</span> <input type="text" id="thisDesc" name="description" style="height: 2rem;" class="span7"></p>
          <p class="row-fluid"><span class="span2">url</span> <input type="text" id="thisUrl" name="url"  style="height: 2rem;" class="span7"></p>
          <p class="row-fluid"><span class="span2">模块</span> <input type="text" id="thisModel" name="model"  style="height: 2rem;" class="span7"></p>
        </div>
      </form>
      <div class="modal-footer">
        <button type="button" class="btn btn-default"
                data-dismiss="modal">关闭
        </button>
        <button type="button" class="btn btn-primary" onclick="permission.updatePerssion()">
          保存
        </button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

   <!--Footer-part-->
<%@include file="/WEB-INF/pages/common/footer.jsp"%>

<!--end-Footer-part-->

<%@include file="/WEB-INF/pages/common/commonJS.jsp"%>

<script src="${basePath}/resources/js/jquery.ui.custom.js"></script>
<script src="${basePath}/resources/js/bootstrap.min.js"></script>
<script src="${basePath}/resources/js/jquery.uniform.js"></script>
<script src="${basePath}/resources/js/select2.min.js"></script>
<script src="${basePath}/resources/js/jquery.dataTables.min.js"></script>
<script src="${basePath}/resources/js/matrix.js"></script>
<%--<script src="${basePath}/resources/js/matrix.tables.js"></script>--%>
<script src="${basePath}/resources/sg/tree/tm_tree.js"></script>


<script>
   $(function(){

       tzAjax.request({
           path:adminPath,
           model:"permission",
           method:"root",
           success:function(data){
             var root = data.root;
             var children = data.children;
             $("#permissiontree").tmTree({outhtml:"<a href='javascript:void(0);' class='remove' title='删除'><i class='fa fa-remove'></i></a><a href='javascript:void(0);' title='新增'  class='add'><i class='fa icon-plus'></i></a><a href='javascript:void(0);' class='edit'><i class='iconfont icon-edit' title='编辑'></i></a>",root:root,children:children,type:"checkbox",onclick:function($obj,data){
               //console.log(JSON.stringify(data));
             },callback:function(opid ,mark){
               if(mark=="remove"){
                   var $this = $(this);
                   //alert("您要删除的opid的是:"+opid);
                   $.tzConfirm({title:"提示",content:"确认删除吗",callback:function(ok){
                       if(ok){
                           $.ajax({
                               url:adminPath+"/permission/delete",
                               beforeSend:function(){loading("请稍后数据执行中...");},
                               type:"post",
                               data:{id:opid},
                               success:function (data) {
                                   if(data==1){
                                       loading("remove");
                                       $this.closest("li").remove();
                                   }
                               }
                           });
                       }
                   }});
               }
               if(mark=="add"){
                   console.log("您要新增的opid的是:"+opid);
                   $('#parentId').val(opid);
                   $('#myModal').modal('show');
               }
               if(mark=="edit"){
                   console.log("您要编辑的opid的是:"+opid);
                   $.ajax({
                       url:adminPath + "/permission/edit",
                       type:"post",
                       data:{id:opid},
                       success:function (data) {
                            console.log('1==='+JSON.stringify(data));
                            $('#thisId').val(opid);
                            $('#thisName').val(data.name);
                            $('#thisDesc').val(data.description);
                            $('#thisUrl').val(data.url);
                            $('#thisModel').val(data.model);
                           $('#myModal2').modal('show');

                       }
                   });
//
               }

             }});
           }
       });

   })


   var permission = {
       savePerssion:function () {
           $("#myForm").submit();
           $('#myModal').modal('hide');
       },
       updatePerssion:function () {
           $("#myForm2").submit();
           $('#myModal2').modal('hide');
       }
   }

   $(function(){
       $('#myModal').on('hidden.bs.modal', function () {
           $('#parentId').val("");
       });
       $('#myModal2').on('hidden.bs.modal', function () {
           $('#thisId').val("");
           $('#thisName').val("");
           $('#thisDesc').val("");
           $('#thisUrl').val("");
           $('#thisModel').val("");
       })
   })
</script>

</body>
</html>
